package com.ego.ware.controller;

import java.util.Arrays;

import com.ego.common.vo.PageVo;
import com.ego.ware.vo.WareInfoSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ego.ware.po.WareInfo;
import com.ego.ware.service.WareInfoService;
import com.ego.common.util.Result;

import javax.validation.Valid;

/**
 * @program: ego
 * @description 仓库信息控制器
 * @author KamTang
 * @date 2022-11-13 13:30:29
 */
@RestController
@RequestMapping("ware")
public class WareInfoController {

    @Autowired
    private WareInfoService wareInfoService;

    /**
     * 搜索
     */
    @PostMapping("/search")
    public Result search(@Valid @RequestBody WareInfoSearchVo search) {
        PageVo<WareInfo> page = wareInfoService.search(search);
        return Result.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
		WareInfo wareInfo = wareInfoService.getById(id);
        return Result.ok().put("wareInfo", wareInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody WareInfo wareInfo){
		wareInfoService.save(wareInfo);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody WareInfo wareInfo){
		wareInfoService.updateById(wareInfo);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		wareInfoService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
